﻿<ComClass(Net控件封装.ClassId, Net控件封装.InterfaceId, Net控件封装.EventsId)>
Public Class Net控件封装

#Region "COM GUID"
    ' 这些 GUID 提供此类的 COM 标识 
    ' 及其 COM 接口。若更改它们，则现有的
    ' 客户端将不再能访问此类。
    Public Const ClassId As String = "b1736ccc-b810-4ed0-8bf3-25af65a4dcd3"
    Public Const InterfaceId As String = "44121bbc-1175-461f-92d4-68b7fc21bb0b"
    Public Const EventsId As String = "c3a99139-0572-41b3-ba03-645480525606"
#End Region

    ' 可创建的 COM 类必须具有一个不带参数的 Public Sub New() 
    ' 否则， 将不会在 
    ' COM 注册表中注册此类，且无法通过
    ' CreateObject 创建此类。
    Public Sub New()
        MyBase.New()
    End Sub

    ''' <summary>
    ''' 调用net的openfiledialog控件
    ''' </summary>
    ''' <param name="文件类型">excel文件</param>
    ''' <param name="文件后缀名">.xls</param>
    ''' <param name="标题"></param>
    ''' <param name="多选">布尔类型</param>
    ''' <returns></returns>
    Public Function 打开文件对话框(文件类型 As String, 文件后缀名 As String, 标题 As String, 多选 As Boolean) As String()
        Dim rtn As New List(Of String)
        Dim ofd As New System.Windows.Forms.OpenFileDialog() With {
            .Multiselect = 多选,
             .Filter = (文件类型 & " (*" & 文件后缀名 & ")|*" & 文件后缀名 & "| All Files (*.*)|*.*"),
             .Title = 标题
        }
        'txt files (*.txt)|*.txt|All files (*.*)|*.*"
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If 多选 Then
                rtn = ofd.FileNames.ToList()
            Else
                rtn = {ofd.FileName}.ToList()
            End If
        End If
        Return rtn.ToArray()
    End Function


    Public Function 保存文件对话框(文件类型 As String, 文件后缀名 As String, 标题 As String) As String
        Dim sfd As New System.Windows.Forms.SaveFileDialog() With {
            .Filter = (文件类型 & " (*" & 文件后缀名 & ")|*" & 文件后缀名 & "| All Files (*.*)|*.*"),
            .Title = 标题
       }
        If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Return sfd.FileName
        Else
            Return String.Empty
        End If
    End Function

End Class


